/**
 * @param {ng.auto.IProvideService} $provide
 * @param {ng.IFilterProvider} $filterProvider
 */
export function filterModuleConfig($provide, $filterProvider) {
  /**
   * @param {string} name
   * @returns {string}
   */
  function greet(name) {
    return `Hello ${name}!`;
  }
  // create a service to demonstrate injection (not always needed)
  $provide.value("greet", greet);
  $provide.service("greet", greet);
  // register a filter factory which uses the
  // greet service to demonstrate DI.
  $filterProvider.register(
    "doGreet",
    /**
     * @param {{(name: string): string}} greet
     * @returns {{(name: string): string}}
     */
    (greet) =>
      // return the filter function which uses the greet service
      // to generate salutation
      /**
       * @param {string} text
       * @returns {string}
       */
      (text) =>
        // filters need to be forgiving so check input validity
        (text && greet(text)) || "none",
  );
}

filterModuleConfig.$inject = ["$provide", "$filterProvider"];

/**
 * @template T
 * @returns {{(inputArray: T[]): T[]}}
 */
export function oddItems() {
  /**
   * @param {T[]} inputArray
   * @returns {T[]}
   */
  return (inputArray) => {
    /**
     * @type {T[]}
     */
    const array = [];
    for (let i = 0; i < inputArray.length; i++) {
      if (i % 2 !== 0) {
        array.push(inputArray[i]);
      }
    }
    return array;
  };
}
